<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>超值选购列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="ebsig_container">

    <!--{include file='comm/menu.tpl'}-->
    <div class="comm_crub">
        <span class="now_crub">超值选购列表</span>
    </div>
    <div class="comm_content">

            <div  class="search-box">
                <div style="position:relative">
                    <form id="searchForm">
                        <table>
                            <tr>
                                <td>
                                    <span>选购活动号：<input type="text" id="goodsChoiceID" name="goodsChoiceID" ></span>
                                    <span>活动名称：<input type="text" id="goodsChoiceName" name="goodsChoiceName"></span>
                                    <span>所属分类 ：<input type="text" id="itemName" name="itemName"></span>
                                    <span>活动日期 ：<input type="text" id="date" name="date" style="width:120px;" readonly="readonly"></span>
                                    <span><input type="button" class="btn" value="查询" onclick="source.search();"></span>
                                    <span><input type="button" class="btn" value="重置" onclick="source.clear();"></span>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/promotion/selection.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "操作", width : 100, align: 'center'},
            {display: "详情", width : 50, align: 'center'},
            {display: "活动号", width : 100, name : "goodsChoiceID", sortable : true},
            {display: "所属分类", width: 120},
            {display: "活动名称", width : 210},
            {display: "活动价格", width : 120},
            {display: "选购数量", width : 120},
            {display: "活动积分", width : 120},
            {display: "起始日期", width : 120},
            {display: "结束日期", width : 120}
        ],
        buttons : [
            {name: "添加", bclass: "add", onpress : "source.add"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "source.check"}
        ],
        sortname: "goodsChoiceID",
        sortorder: "asc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true
    });

    var source = {
        //goodsChoiceID
        pubChoiceID: '',
        //useFlg
        pubFlg: '',
        //打开折叠表格
        openList: function (choice_id){
            //生成传入参数
            var dt = $('#searchForm').serializeArray();
            dt.push({'name':'choice_id','value':choice_id});
            //刷新页面
            $("#flex").flexOptions({params: dt}).flexReload();
        },
        //关上折叠表格
        closeList: function (){
            var dt = $('#searchForm').serializeArray();
            dt.push({'name':'choice_id','value':''});
            $("#flex").flexOptions({params: dt}).flexReload();
        },
        //查找
        search: function() {
            var dt = $('#searchForm').serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },
        //重置表单
        clear: function() {
            document.forms['searchForm'].reset();
        },
        //新增（choice_type：1邮购、2网站，写死）
        add: function(){
            E.open("/quanliadmin/app/promotion/selection.pscript?operFlg=2&choice_type=2",'',{height : 600,width : 1133, top :20 ,left : 150});
        },
        //编辑（choice_type：1邮购、2网站，写死）
        detail: function(goodsChoiceID){
            E.open("/quanliadmin/app/promotion/selection.pscript?operFlg=3&choice_type=2&goodsChoiceID="+goodsChoiceID,'',{height : 600,width : 1133, top :20 ,left : 150});
        },
        //详情（choice_type：1邮购、2网站，写死）
        info: function(goodsChoiceID){
            E.open("/quanliadmin/app/promotion/selection.pscript?operFlg=4&goodsChoiceID="+goodsChoiceID,'',{height : 600,width : 980, top :20 ,left : 150});
        },
        //启用禁用确认
        edit: function(obj,goodsChoiceID){
            var msg = $(obj).html();
            this.pubChoiceID = goodsChoiceID;
            if (msg == '启用'){
                this.pubFlg = 1;
                E.confirm("您确定禁用该超值选购吗？", "source.change");
            }else if (msg == '禁用'){
                this.pubFlg = 0;
                source.change();
            }
        },
        //启用禁用
        change: function(){
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/promotion/selection.ajax?operFlg=6",
                dataType: "JSON",
                data:{'goodsChoiceID':source.pubChoiceID, 'changeFlg':source.pubFlg},
                success: function(result_obj){
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "source.load");
                    }
                    else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
        pubChoiceIDArr: new Array(),
        //删除确认
        check: function(){
            //获取选中的行的行数
            var selected_count=$('.trSelected',flex).length;
            if (selected_count==0) {
                E.alert('请选择要删除的商品套装');
                return;
            }else{
                var choiceIDArr = new Array();
                for(var i=0; i<selected_count; i++){
                    var choiceIDStr = $('.trSelected',flex).eq(i).attr('id');
                    var choiceID = choiceIDStr.substr(3);
                    choiceIDArr.push(choiceID);
                }
                this.pubChoiceIDArr = choiceIDArr;

                //弹出确认层
                E.confirm('是否删除这 ' + $('.trSelected',flex).length + ' 个超值选购吗?', "source.del");
            }
        },
        //删除
        del: function(){
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/promotion/selection.ajax?operFlg=4",
                dataType: "JSON",
                data:{'choiceIDArr': source.pubChoiceIDArr},
                success: function(result_obj){
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "source.load");
                    }
                    else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
        load: function(){
            $("#flex").flexReload();
        }
    };

    $('#date').datetimepicker();

</script>

</body>
</html>